package ihm.views.main.catalog;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

public class CatalogModel extends AbstractTableModel {

  private static final long serialVersionUID = 1L;

  private String[] columnsName = {"Name", "Level", "Quality", "Type", "Id"};
  private ArrayList<CatalogEntry> data = new ArrayList<CatalogEntry>();

  public CatalogModel(String[] columnsName)
  {
    super();
    this.columnsName = columnsName;
  }

  public void updateData(ArrayList<CatalogEntry> newData)
  {
    this.data = newData;
    this.fireTableDataChanged();
  }

  public void updateColumns(String[] newColumnsName)
  {
    this.columnsName = newColumnsName;
    this.fireTableStructureChanged();
  }
  
  @Override
  public int getColumnCount() {
    return this.columnsName.length;
  }

  public String getColumnName(int columnIndex) {
    return this.columnsName[columnIndex];
  }
  
  @Override
  public int getRowCount() {
    return this.data.size();
  }

  @Override
  public Object getValueAt(int rowIndex, int columnIndex) {
    CatalogEntry entry = this.data.get(rowIndex);
    
    switch(columnIndex)
    {
      case 0: return entry.getName();
      case 1: return entry.getLevel();
      case 2: return entry.getQuality();
      case 3: return entry.getType();
      case 4: return entry.getId();
    }
      return this.data.get(rowIndex);
  }

}
